﻿using System.Linq;
using System.Web.Mvc;
using Lu.Blog.Domain.Model.DocumentType;
using Lu.Blog.Domain.Provider;
using Lu.Blog.Models;
using umbraco.interfaces;
using umbraco.MacroEngines;
using Umbraco.Web.Mvc;
using Vega.USiteBuilder;

namespace Lu.Blog.Controllers
{
    public class MenuSurfaceController : SurfaceController
    {

        private readonly IMenuProvider _menuProvider;

        public MenuSurfaceController(IMenuProvider menuProvider)
        {
            _menuProvider = menuProvider;
        }
        //
        // GET: /MenuSurface/

        public ActionResult Index()
        {
            var menuItems = _menuProvider.GetMainMenu(new DynamicNode(-1).ChildrenAsList.First<INode>());
            var viewModel = new MenuViewModel
            {
                Items = menuItems,
                Page =
                    (UmbracoContext.PageId.HasValue && ContentHelper.GetByNodeId(UmbracoContext.PageId.Value) is BaseNavigation
                        ? ContentHelper.GetByNodeId<BaseNavigation>(UmbracoContext.PageId.Value)
                        : null)
            };
            return PartialView("Menu", viewModel);
        }
    }
}